package com.mvp.lt.airlineview.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.EditText;

import com.mvp.lt.airlineview.utils.DensityUtils;

/**
 * $activityName
 *
 * @author LiuTao
 * @date 2019/3/1/001
 */


@SuppressLint("AppCompatCustomView")
public class LinedEditText extends EditText {
    public LinedEditText(Context context) {
        super(context);
        initPaint();
    }


    public LinedEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        initPaint();
    }


    public LinedEditText(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initPaint();
    }


    private void initPaint() {
//        mPaint.setStyle(Paint.Style.STROKE);
////        mPaint.setColor(0x80000000);
//    	mPaint.setStyle(Paint.Style.STROKE);
//    	mPaint.setColor(R.color.dashed_line_color);
//        PathEffect effects = new DashPathEffect(new float[]{5,5,5,5},1);
//        mPaint.setPathEffect(effects);
    }


    @Override protected void onDraw(Canvas canvas) {
        Paint mPaint = new Paint();
//       mPaint.setColor(0x80000000);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(1);
        mPaint.setColor(Color.BLACK);

        int right = getRight();
        int paddingTop = getPaddingTop();
        int paddingBottom = getPaddingBottom();
        int paddingLeft = getPaddingLeft();
        int paddingRight = getPaddingRight();
        int height = getHeight();
        int lineHeight = getLineHeight();
        int spacingHeight = (int) DensityUtils.dpToPx(2);
        if (Build.VERSION.SDK_INT >= 16) {
            spacingHeight = (int) getLineSpacingExtra();
        }
        height = height + spacingHeight;//把最后一个行间距也计算进去
        int count = (height - paddingTop - paddingBottom) / lineHeight;


        for (int i = 0; i < count; i++) {
            int baseline = lineHeight * (i + 1);
            canvas.drawLine(0 + paddingLeft, baseline, right - paddingRight, baseline, mPaint);
        }
        super.onDraw(canvas);
    }

}
